﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	internal static class GenParse_NetStatus
	{
		#region private constants

		private const byte OKByte = 0x00;
		private const byte OutageByte = 0x08;
		private const byte BusyByte = 0x10;
		private const byte SubscriberNotReachableByte = 0x11;
		private const byte WrongNumberByte = 0x12;
		private const byte TransparentASCIIReportByte = 0x80;

		#endregion private constants

		#region internal methods

		internal static byte GenerateByte(eNetStatus netStatus)
		{
			byte netStatusByte = 0x00;

			switch (netStatus)
			{
				case eNetStatus.OK:
					netStatusByte = OKByte;
					break;
				case eNetStatus.Outage:
					netStatusByte = OutageByte;
					break;
				case eNetStatus.Busy:
					netStatusByte = BusyByte;
					break;
				case eNetStatus.SubscriberNotReachable:
					netStatusByte = SubscriberNotReachableByte;
					break;
				case eNetStatus.WrongNumber:
					netStatusByte = WrongNumberByte;
					break;
				case eNetStatus.TransparentASCIIReport:
					netStatusByte = TransparentASCIIReportByte;
					break;
				
				default:
					// TODO handle error (unknown value for eNetStatus)
					break;
			}

			return netStatusByte;
		}

		internal static bool ParseByte(byte netStatusByte, out eNetStatus netStatus)
		{
			// set default value
			bool bRetVal = true;
			netStatus = eNetStatus.OK;

			switch (netStatusByte)
			{
				case OKByte:
					netStatus = eNetStatus.OK;
					break;
				case OutageByte:
					netStatus = eNetStatus.Outage;
					break;
				case BusyByte:
					netStatus = eNetStatus.Busy;
					break;
				case SubscriberNotReachableByte:
					netStatus = eNetStatus.SubscriberNotReachable;
					break;
				case WrongNumberByte:
					netStatus = eNetStatus.WrongNumber;
					break;
				case TransparentASCIIReportByte:
					netStatus = eNetStatus.TransparentASCIIReport;
					break;
				
				default:
					// TODO handle error (unknown value for netStatusByte)
					bRetVal = false;
					break;
			}

			return bRetVal;
		}

		#endregion internal methods
	}
}
